define([], function() {
	return {
		title: ['<a href="user.html">外卖中心</a>', "菜品管理"],
		init: function(content){
			let form = content.children("form");
			let table = content.children("table");
			let search = [];
			let foodGoodsId = content.find("select[name='foodGoodsId']");
			let tableInit = function() {
				
				let actionEvent = {
						
						
						"click .btn-danger":function(e, value, row){
							
							if(confirm("确定要删除这个菜品吗？")){
								$.post(
										"food/foodgoods/delete.do",{
											"foodGoodsId":row.foodGoodsId
										},
										function(data){
											if(data.ok){
												toastr.success("删除成功");
												window.location.reload();
											}else{
												toastr.error("删除失败:"+data.message);
											}
										},"json"
									);
							}
							
						}
				};
				
			table.bootstrapTable({
				url: 'food/foodgoods/getlist.do', // 表格数据来源
				method: "get",
				sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
				pageNumber: 1, //初始化加载第一页，默认第一页
				pageSize: 5, //每页的记录行数（*）
				pageList: [5, 10, 15, 20, 30, 50], //可供选择的每页的行数（*）
				pagination: true, //是否显示分页（*）
				dataField: "list",
				toolbar: form,
				queryParamsType: "",
				queryParams: function(p) {
					let ps = [].concat(search);
					ps.push({
						"name": "current",
						"value": p.pageNumber
					});
					ps.push({
						"name": "rowMax",
						"value": p.pageSize
					});
					ps.push({
						"name": "sortName",
						"value": p.sortName
					});
					ps.push({
						"name": "sortOrder",
						"value": p.sortOrder
					});
					return ps;
				},
				columns: [{
						field: 'foodGoodsName',
						title: '商品名称',
						align: "center",
						width: 50
					}, {
						field: 'foodGoodsDescribes',
						title: '介绍',
						align: "center",
						width: 250,
					}, {
						field: '',
						title: '图片',
						align: "center",
						width: 120,
						formatter: function(value, row, index, field) {
							return "<img style='width: 10em;height: 8em;' src="+'"'+row.foodGoodsImg+'"'+"/>";
						}
					},{
						field: 'foodGoodsPrice',
						title: '价格',
						align: "center",
						sortable: true,
						sortName: "food_goods_price",
						width: 50
					}, {
						
						title: '操作',
						width: 50,
						align: "center",
						events: actionEvent,
						formatter: function(value, row, index, field) {
							return '<a class="btn btn-warning" href="/food/foodgoods/get.do?foodGoodsId='+row.foodGoodsId+'">修改</a> <a href="javascript:void(0);"  class="btn btn-danger">删除</a>';
						}
					}
				]
			});
		};
		$.get(
			"food/foodgoods/getlist.do",
			function(data) {
				tableInit();
			}, "json"
		);
		}
	}
});